home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / redisplay-output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-26  |  37.8 KB  |  1,322 lines

  1. /* Synchronize redisplay structures and output changes.
  2.    Copyright (C) 1994, 1995 Board of Trustees, University of Illinois
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: Not in FSF. */
  21.  
  22. /* This file has been Mule-ized. */
  23.  
  24. /* Author: Chuck Thompson */
  25.  
  26. #include <config.h>
  27. #include "lisp.h"
  28. #include "debug.h"
  29.  
  30. #include "buffer.h"
  31. #include "window.h"
  32. #include "frame.h"
  33. #include "device.h"
  34. #include "glyphs.h"
  35. #include "redisplay.h"
  36. #include "faces.h"
  37.  
  38. #include "sysdep.h"
  39.  
  40. static int compare_runes (struct window *w, struct rune *crb,
  41.               struct rune *drb);
  42. static void redraw_cursor_in_window (struct window *w,
  43.                      int run_end_begin_glyphs);
  44. void redisplay_output_window (struct window *w);
  45.  
  46. /*****************************************************************************
  47.  sync_rune_structs
  48.  
  49.  Synchronize the given rune blocks.
  50.  ****************************************************************************/
  51. static void
  52. sync_rune_structs (struct window *w, rune_dynarr *cra, rune_dynarr *dra)
  53. {
  54.   int rune_elt;
  55.   int max_move = ((Dynarr_length (dra) > Dynarr_largest (cra))
  56.           ? Dynarr_largest (cra)
  57.           : Dynarr_length (dra));
  58.  
  59.   if (max_move)
  60.     {
  61.       /* #### Doing this directly breaks the encapsulation.  But, the
  62.          running time of this function has a measurable impact on
  63.          redisplay performance so avoiding all excess overhead is a
  64.          good thing.  Is all of this true? */
  65.       memcpy (cra->base, dra->base, sizeof (struct rune) * max_move);
  66.       Dynarr_set_size (cra, max_move);
  67.     }
  68.   else
  69.     Dynarr_reset (cra);
  70.  
  71.   for (rune_elt = max_move; rune_elt < Dynarr_length (dra); rune_elt++)
  72.     {
  73.       struct rune rb, *crb;
  74.       struct rune *drb = Dynarr_atp (dra, rune_elt);
  75.  
  76.       crb = &rb;
  77.       memcpy (crb, drb, sizeof (struct rune));
  78.       Dynarr_add (cra, *crb);
  79.     }
  80. }
  81.  
  82. /*****************************************************************************
  83.  sync_display_line_structs
  84.  
  85.  For the given LINE in window W, make the current display line equal
  86.  the desired display line.
  87.  ****************************************************************************/
  88. static void
  89. sync_display_line_structs (struct window *w, int line, int do_blocks,
  90.                display_line_dynarr *cdla,
  91.                display_line_dynarr *ddla)
  92. {
  93.   int cdla_len = Dynarr_length (cdla);
  94.  
  95.   struct display_line dl, *clp, *dlp;
  96.   int db_elt;
  97.  
  98.   dlp = Dynarr_atp (ddla, line);
  99.   if (line >= Dynarr_largest (cdla))
  100.     {
  101.       clp = &dl;
  102.       clp->display_blocks = Dynarr_new (struct display_block);
  103.     }
  104.   else
  105.     {
  106.       clp = Dynarr_atp (cdla, line);
  107.       if (clp->display_blocks)
  108.     Dynarr_reset (clp->display_blocks);
  109.       if (clp->left_glyphs)
  110.     {
  111.       Dynarr_free (clp->left_glyphs);
  112.       clp->left_glyphs = 0;
  113.     }
  114.       if (clp->right_glyphs)
  115.     {
  116.       Dynarr_free (clp->right_glyphs);
  117.       clp->right_glyphs = 0;
  118.     }
  119.     }
  120.   {
  121.     display_block_dynarr *tdb = clp->display_blocks;
  122.  
  123.     memcpy (clp, dlp, sizeof (struct display_line));
  124.     clp->display_blocks = tdb;
  125.     clp->left_glyphs = 0;
  126.     clp->right_glyphs = 0;
  127.   }
  128.  
  129.   if (!do_blocks && line >= cdla_len)
  130.     {
  131.       Dynarr_add (cdla, *clp);
  132.       return;
  133.     }
  134.  
  135.   for (db_elt = 0; db_elt < Dynarr_length (dlp->display_blocks); db_elt++)
  136.     {
  137.       struct display_block db, *cdb;
  138.       struct display_block *ddb = Dynarr_atp (dlp->display_blocks, db_elt);
  139.  
  140.       if (db_elt >= Dynarr_largest (clp->display_blocks))
  141.     {
  142.       cdb = &db;
  143.       memcpy (cdb, ddb, sizeof (struct display_block));
  144.       cdb->runes = Dynarr_new (struct rune);
  145.       Dynarr_add (clp->display_blocks, *cdb);
  146.     }
  147.       else
  148.     {
  149.       rune_dynarr *tr;
  150.  
  151.       cdb = Dynarr_atp (clp->display_blocks, db_elt);
  152.       tr = cdb->runes;
  153.       memcpy (cdb, ddb, sizeof (struct display_block));
  154.       cdb->runes = tr;
  155.       Dynarr_increment (clp->display_blocks);
  156.     }
  157.  
  158.       sync_rune_structs (w, cdb->runes, ddb->runes);
  159.     }
  160.  
  161.   if (line >= cdla_len)
  162.     Dynarr_add (cdla, *clp);
  163. }
  164.  
  165. /*****************************************************************************
  166.  compare_runes
  167.  
  168.  Compare to runes to see if each of their fields is equal.  If so,
  169.  return true otherwise return false.
  170.  ****************************************************************************/
  171. static int
  172. compare_runes (struct window *w, struct rune *crb, struct rune *drb)
  173. {
  174.   /* Do not compare the values of bufpos and endpos.  They do not
  175.      affect the display characteristics. */
  176.  
  177.   if ((crb->findex != drb->findex) ||
  178.       (FACE_CACHE_ELEMENT_DIRTY (w, drb->findex)))
  179.     return 0;
  180.   else if (!EQ (crb->extent, drb->extent))
  181.     return 0;
  182.   else if (crb->xpos != drb->xpos)
  183.     return 0;
  184.   else if (crb->width != drb->width)
  185.     return 0;
  186.   else if (crb->cursor_type != drb->cursor_type)
  187.     return 0;
  188.   else if (crb->type != drb->type)
  189.     return 0;
  190.   else if (crb->type == CHAR && (crb->object.ch != drb->object.ch))
  191.     return 0;
  192.   else if (crb->type == DGLYPH &&
  193.        (!EQ (crb->object.dglyph.glyph, drb->object.dglyph.glyph) ||
  194.         crb->object.dglyph.xoffset != drb->object.dglyph.xoffset))
  195.     return 0;
  196.   else if (crb->type == HLINE &&
  197.        (crb->object.hline.thickness != drb->object.hline.thickness ||
  198.         crb->object.hline.yoffset != drb->object.hline.yoffset))
  199.     return 0;
  200.   else
  201.     return 1;
  202. }
  203.  
  204. /*****************************************************************************
  205.  get_next_display_block
  206.  
  207.  Return the next display starting at or overlapping START_POS.  Return
  208.  the start of the next region in NEXT_START.
  209.  ****************************************************************************/
  210. int
  211. get_next_display_block (layout_bounds bounds, display_block_dynarr *dba,
  212.             int start_pos, int *next_start)
  213. {
  214.   int next_display_block = NO_BLOCK;
  215.   int priority = -1;
  216.   int block;
  217.  
  218.   /* If we don't find a display block covering or starting at
  219.      start_pos, then we return the starting point of the next display
  220.      block or the next division boundary, whichever is closer to
  221.      start_pos. */
  222.   if (next_start)
  223.     {
  224.       if (start_pos >= bounds.left_out && start_pos < bounds.left_in)
  225.     *next_start = bounds.left_in;
  226.       else if (start_pos < bounds.left_white)
  227.     *next_start = bounds.left_white;
  228.       else if (start_pos < bounds.right_white)
  229.     *next_start = bounds.right_white;
  230.       else if (start_pos < bounds.right_in)
  231.     *next_start = bounds.right_in;
  232.       else if (start_pos <= bounds.right_out)
  233.     *next_start = bounds.right_out;
  234.       else
  235.     abort ();
  236.     }
  237.  
  238.   for (block = 0; block < Dynarr_length (dba); block++)
  239.     {
  240.       struct display_block *db = Dynarr_atp (dba, block);
  241.  
  242.       if (db->start_pos <= start_pos && db->end_pos > start_pos)
  243.     {
  244.       if ((int) db->type > priority)
  245.         {
  246.           priority = db->type;
  247.           next_display_block = block;
  248.           if (next_start)
  249.         *next_start = db->end_pos;
  250.         }
  251.     }
  252.       else if (next_start && db->start_pos > start_pos)
  253.     {
  254.       if (db->start_pos < *next_start)
  255.         *next_start = db->start_pos;
  256.     }
  257.     }
  258.  
  259.   return next_display_block;
  260. }
  261.  
  262. /*****************************************************************************
  263.  get_cursor_size_and_location
  264.  
  265.  Return the information defining the pixel location of the cursor.
  266.  ****************************************************************************/
  267. static void
  268. get_cursor_size_and_location (struct window *w, struct display_block *db,
  269.                   int cursor_location,
  270.                   int *cursor_start, int *cursor_width,
  271.                   int *cursor_height)
  272. {
  273.   struct device *d = XDEVICE (XFRAME (w->frame)->device);
  274.   struct rune *rb;
  275.   struct font_metric_info fm;
  276.  
  277.   if (Dynarr_length (db->runes) <= cursor_location)
  278.     abort ();
  279.  
  280.   rb = Dynarr_atp (db->runes, cursor_location);
  281.   *cursor_start = rb->xpos;
  282.  
  283.   DEVMETH (d, font_metric_info, (d, FACE_CACHE_ELEMENT_FONT (w, DEFAULT_INDEX),
  284.                  &fm));
  285.   *cursor_height = fm.height;
  286.  
  287.   if (rb->type == BLANK)
  288.     *cursor_width = fm.width;
  289.   else
  290.     *cursor_width = rb->width;
  291. }
  292.  
  293. /*****************************************************************************
  294.  compare_display_blocks
  295.  
  296.  Given two display blocks, output only those areas where they differ.
  297.  ****************************************************************************/
  298. static int
  299. compare_display_blocks (struct window *w, struct display_line *cdl,
  300.             struct display_line *ddl, int c_block, int d_block,
  301.             int start_pixpos, int cursor_start, int cursor_width,
  302.             int cursor_height)
  303. {
  304.   struct frame *f = XFRAME (w->frame);
  305.   struct device *d = XDEVICE (f->device);
  306.  
  307.   struct display_block *cdb, *ddb;
  308.   int start_pos;
  309.   int stop_pos;
  310.   int force = 0;
  311.   int block_end;
  312.  
  313.   cdb = Dynarr_atp (cdl->display_blocks, c_block);
  314.   ddb = Dynarr_atp (ddl->display_blocks, d_block);
  315.  
  316.   assert (cdb->type == ddb->type);
  317.  
  318.   start_pos = -1;
  319.   stop_pos = min (Dynarr_length (cdb->runes), Dynarr_length (ddb->runes));
  320.  
  321.   block_end =
  322.     (!Dynarr_length (ddb->runes)
  323.      ? 0
  324.      : (Dynarr_atp (ddb->runes, Dynarr_length (ddb->runes) - 1)->xpos +
  325.     Dynarr_atp (ddb->runes, Dynarr_length (ddb->runes) - 1)->width));
  326.  
  327.   /* If the new block type is not text and the cursor status is
  328.      changing and it overlaps the position of this block then force a
  329.      full redraw of the block in order to make sure that the cursor is
  330.      updated properly. */
  331.   if (ddb->type != TEXT
  332.       && ((cdl->cursor_elt == -1 && ddl->cursor_elt != -1)
  333.       || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1))
  334.       && (ddl->cursor_elt == -1 ||
  335.       (cursor_start
  336.        && cursor_width
  337.        && (cursor_start + cursor_width) >= start_pixpos
  338.        && cursor_start <= block_end)))
  339.     force = 1;
  340.  
  341.   if (f->windows_structure_changed ||
  342.       f->faces_changed ||
  343.       cdl->ypos != ddl->ypos ||
  344.       cdl->ascent != ddl->ascent ||
  345.       cdl->descent != ddl->descent ||
  346.       cdl->clip != ddl->clip ||
  347.       force)
  348.     {
  349.       start_pos = 0;
  350.       force = 1;
  351.     }
  352.   else
  353.     {
  354.       int elt = 0;
  355.  
  356.       while (start_pos < 0 && elt < stop_pos)
  357.     {
  358.       if (!compare_runes (w, Dynarr_atp (cdb->runes, elt),
  359.                   Dynarr_atp (ddb->runes, elt)))
  360.         {
  361.           start_pos = elt;
  362.         }
  363.       else
  364.         {
  365.           elt++;
  366.         }
  367.     }
  368.  
  369.       /* If nothing has changed in the area where the blocks overlap, but
  370.      there are new blocks in the desired block, then adjust the start
  371.      point accordingly. */
  372.       if (elt == stop_pos && stop_pos < Dynarr_length (ddb->runes))
  373.     start_pos = stop_pos;
  374.     }
  375.  
  376.   if (start_pos >= 0)
  377.     {
  378.       if ((Dynarr_length (ddb->runes) != Dynarr_length (cdb->runes))
  379.       || force)
  380.     {
  381.       stop_pos = Dynarr_length (ddb->runes);
  382.     }
  383.       else
  384.     {
  385.       /* If the lines have the same number of runes and we are not
  386.          forcing a full redraw because the display line has
  387.          changed position then we try and optimize how much of the
  388.          line we actually redraw by scanning backwards from the
  389.          end for the first changed rune.  This optimization is
  390.          almost always triggered by face changes. */
  391.  
  392.       int elt = Dynarr_length (ddb->runes) - 1;
  393.  
  394.       while (elt > start_pos)
  395.         {
  396.           if (!compare_runes (w, Dynarr_atp (cdb->runes, elt),
  397.                   Dynarr_atp (ddb->runes, elt)))
  398.         break;
  399.           else
  400.         elt--;
  401.         }
  402.       stop_pos = elt + 1;
  403.     }
  404.  
  405.       DEVMETH (d, output_display_block, (w, ddl, d_block, start_pos,
  406.                      stop_pos, start_pixpos,
  407.                      cursor_start, cursor_width,
  408.                      cursor_height));
  409.       return 1;
  410.     }
  411.  
  412.   return 0;
  413. }
  414.  
  415. /*****************************************************************************
  416.  clear_left_border
  417.  
  418.  Clear the lefthand outside border.
  419.  ****************************************************************************/
  420. static void
  421. clear_left_border (struct window *w, int y, int height)
  422. {
  423.   struct frame *f = XFRAME (w->frame);
  424.   struct device *d = XDEVICE (f->device);
  425.   Lisp_Object window;
  426.  
  427.   XSETWINDOW (window, w);
  428.   DEVMETH (d, clear_region, (window, DEFAULT_INDEX,
  429.                  FRAME_LEFT_BORDER_START (f), y,
  430.                  FRAME_BORDER_WIDTH (f), height));
  431. }
  432.  
  433. /*****************************************************************************
  434.  clear_right_border
  435.  
  436.  Clear the righthand outside border.
  437.  ****************************************************************************/
  438. static void
  439. clear_right_border (struct window *w, int y, int height)
  440. {
  441.   struct frame *f = XFRAME (w->frame);
  442.   struct device *d = XDEVICE (f->device);
  443.   Lisp_Object window;
  444.  
  445.   XSETWINDOW (window, w);
  446.   DEVMETH (d, clear_region, (window, DEFAULT_INDEX,
  447.                  FRAME_RIGHT_BORDER_START (f),
  448.                  y, FRAME_BORDER_WIDTH (f), height));
  449. }
  450.  
  451. /*****************************************************************************
  452.  output_display_line
  453.  
  454.  Ensure that the contents of the given display line is correct
  455.  on-screen.  The force_ parameters are used by redisplay_move_cursor
  456.  to correctly update cursor locations and only cursor locations.
  457.  ****************************************************************************/
  458. void
  459. output_display_line (struct window *w, display_line_dynarr *cdla,
  460.              display_line_dynarr *ddla, int line, int force_start,
  461.              int force_end)
  462.  
  463. {
  464.   struct frame *f = XFRAME (w->frame);
  465.   struct device *d = XDEVICE (f->device);
  466.   struct buffer *b = XBUFFER (w->buffer);
  467.   struct buffer *old_b = window_display_buffer (w);
  468.   struct display_line *cdl, *ddl;
  469.   display_block_dynarr *cdba, *ddba;
  470.   int start_pixpos, end_pixpos;
  471.   int cursor_start, cursor_width, cursor_height;
  472.  
  473.   int force = (force_start >= 0 || force_end >= 0);
  474.   int clear_border = 0;
  475.   int must_sync = 0;
  476.  
  477.   if (cdla && line < Dynarr_length (cdla))
  478.     {
  479.       cdl = Dynarr_atp (cdla, line);
  480.       cdba = cdl->display_blocks;
  481.     }
  482.   else
  483.     {
  484.       cdl = NULL;
  485.       cdba = NULL;
  486.     }
  487.  
  488.   ddl = Dynarr_atp (ddla, line);      /* assert line < Dynarr_length (ddla) */
  489.   ddba = ddl->display_blocks;
  490.  
  491.   if (force_start >= 0 && force_start >= ddl->bounds.left_out)
  492.     start_pixpos = force_start;
  493.   else
  494.     start_pixpos = ddl->bounds.left_out;
  495.  
  496.   if (force_end >= 0 && force_end < ddl->bounds.right_out)
  497.     end_pixpos = force_end;
  498.   else
  499.     end_pixpos = ddl->bounds.right_out;
  500.  
  501.   /* Get the cursor parameters. */
  502.   if (ddl->cursor_elt != -1)
  503.     {
  504.       struct display_block *db;
  505.  
  506.       /* If the lines cursor parameter is not -1 then it indicates
  507.          which rune in the TEXT block contains the cursor.  This means
  508.          that there must be at least one display block.  The TEXT
  509.          block, if present, must always be the first display block. */
  510.       assert (Dynarr_length (ddba) != 0);
  511.  
  512.       db = Dynarr_atp (ddba, 0);
  513.       assert (db->type == TEXT);
  514.  
  515.       get_cursor_size_and_location (w, db, ddl->cursor_elt, &cursor_start,
  516.                     &cursor_width, &cursor_height);
  517.     }
  518.   else
  519.     {
  520.       cursor_start = cursor_width = cursor_height = 0;
  521.     }
  522.  
  523.   /* The modeline should only have a single block and it had better be
  524.      a TEXT block. */
  525.   if (ddl->modeline)
  526.     {
  527.       /* The shadow thickness check is necesssary if only the sign of
  528.          the size changed. */
  529.       if (cdba && !w->shadow_thickness_changed)
  530.     {
  531.       must_sync |= compare_display_blocks (w, cdl, ddl, 0, 0,
  532.                            start_pixpos, 0, 0, 0);
  533.     }
  534.       else
  535.     {
  536.       DEVMETH (d, output_display_block, (w, ddl, 0, 0, -1, start_pixpos,
  537.                          0, 0, 0));
  538.       must_sync = 1;
  539.     }
  540.  
  541.       if (must_sync)
  542.     clear_border = 1;
  543.     }
  544.  
  545.   while (!ddl->modeline && start_pixpos < end_pixpos)
  546.     {
  547.       int block;
  548.       int next_start_pixpos;
  549.  
  550.       block = get_next_display_block (ddl->bounds, ddba, start_pixpos,
  551.                       &next_start_pixpos);
  552.  
  553.       /* If we didn't find a block then we should blank the area
  554.          between start_pos and next_start if necessary. */
  555.       if (block == NO_BLOCK)
  556.     {
  557.       /* We only erase those areas which were actually previously
  558.              covered by a display block unless the window structure
  559.              changed.  In that case we clear all areas since the current
  560.              structures may actually represent a different buffer. */
  561.       while (start_pixpos < next_start_pixpos)
  562.         {
  563.           int block_end;
  564.           int old_block;
  565.  
  566.           if (cdba)
  567.         old_block = get_next_display_block (ddl->bounds, cdba,
  568.                             start_pixpos, &block_end);
  569.           else
  570.         {
  571.           old_block = NO_BLOCK;
  572.           block_end = next_start_pixpos;
  573.         }
  574.  
  575.           if (!cdba || old_block != NO_BLOCK || b != old_b ||
  576.           f->windows_structure_changed ||
  577.           f->faces_changed ||
  578.           force ||
  579.           (cdl && (cdl->ypos != ddl->ypos ||
  580.                cdl->ascent != ddl->ascent ||
  581.                cdl->descent != ddl->descent ||
  582.                cdl->clip != ddl->clip)))
  583.         {
  584.           int x, y, width, height;
  585.           Lisp_Object face;
  586.  
  587.           must_sync = 1;
  588.           x = start_pixpos;
  589.           y = ddl->ypos - ddl->ascent;
  590.           width = min (next_start_pixpos, block_end) - x;
  591.           height = ddl->ascent + ddl->descent - ddl->clip;
  592.  
  593.           if (x < ddl->bounds.left_in)
  594.             face = Vleft_margin_face;
  595.           else if (x < ddl->bounds.right_in)
  596.             face = Vdefault_face;
  597.           else if (x < ddl->bounds.right_out)
  598.             face = Vright_margin_face;
  599.           else
  600.             face = Qnil;
  601.  
  602.           if (!NILP (face))
  603.             {
  604.               Lisp_Object window;
  605.  
  606.               XSETWINDOW (window, w);
  607.  
  608.               /* Clear the empty area. */
  609.               DEVMETH (d, clear_region,
  610.                    (window, get_builtin_face_cache_index (w, face),
  611.                 x, y, width, height));
  612.  
  613.               /* Mark that we should clear the border.  This is
  614.              necessary because italic fonts may leave
  615.              droppings in the border. */
  616.               clear_border = 1;
  617.             }
  618.         }
  619.  
  620.           start_pixpos = min (next_start_pixpos, block_end);
  621.         }
  622.     }
  623.       else
  624.     {
  625.       struct display_block *cdb, *ddb;
  626.       int block_end;
  627.       int old_block;
  628.  
  629.       if (cdba)
  630.         old_block = get_next_display_block (ddl->bounds, cdba,
  631.                         start_pixpos, &block_end);
  632.       else
  633.         old_block = NO_BLOCK;
  634.  
  635.       ddb = Dynarr_atp (ddba, block);
  636.       cdb = (old_block != NO_BLOCK ? Dynarr_atp (cdba, old_block) : 0);
  637.  
  638.       /* If there was formerly no block over the current
  639.          region or if it was a block of a different type, then
  640.          output the entire ddb.  Otherwise, compare cdb and
  641.          ddb and output only the changed region. */
  642.       if (!force && cdb && ddb->type == cdb->type && b == old_b)
  643.         {
  644.           must_sync |= compare_display_blocks (w, cdl, ddl, old_block,
  645.                            block, start_pixpos,
  646.                            cursor_start, cursor_width,
  647.                            cursor_height);
  648.         }
  649.       else
  650.         {
  651.           int elt;
  652.           int first_elt = 0;
  653.           int last_elt = -1;
  654.  
  655.           for (elt = 0; elt < Dynarr_length (ddb->runes); elt++)
  656.         {
  657.           struct rune *rb = Dynarr_atp (ddb->runes, elt);
  658.  
  659.           if (start_pixpos >= rb->xpos
  660.               && start_pixpos < rb->xpos + rb->width)
  661.             first_elt = elt;
  662.  
  663.           if (end_pixpos > rb->xpos
  664.               && end_pixpos <= rb->xpos + rb->width)
  665.             {
  666.               last_elt = elt + 1;
  667.               if (last_elt > Dynarr_length (ddb->runes))
  668.             last_elt = Dynarr_length (ddb->runes);
  669.               break;
  670.             }
  671.         }
  672.  
  673.           must_sync = 1;
  674.           DEVMETH (d, output_display_block, (w, ddl, block, first_elt,
  675.                          last_elt,
  676.                          start_pixpos,
  677.                          cursor_start, cursor_width,
  678.                          cursor_height));
  679.         }
  680.  
  681.       start_pixpos = next_start_pixpos;
  682.     }
  683.     }
  684.  
  685.   /* Clear the internal border if we are next to it and the window
  686.      structure or frame size has changed or if something caused
  687.      clear_border to be tripped.  */
  688.   /* #### Doing this on f->clear sucks but is necessary because of
  689.      window-local background values. */
  690.   if (f->windows_structure_changed || f->faces_changed || clear_border
  691.       || f->clear)
  692.     {
  693.       int y = ddl->ypos - ddl->ascent;
  694.       int height = ddl->ascent + ddl->descent - ddl->clip;
  695.  
  696.       if (ddl->modeline)
  697.     {
  698.       y -= MODELINE_SHADOW_THICKNESS (w);
  699.       height += (2 * MODELINE_SHADOW_THICKNESS (w));
  700.     }
  701.  
  702.       if (window_is_leftmost (w))
  703.     clear_left_border (w, y, height);
  704.       if (window_is_rightmost (w))
  705.     clear_right_border (w, y, height);
  706.     }
  707.  
  708.   if (cdla)
  709.     sync_display_line_structs (w, line, must_sync, cdla, ddla);
  710. }
  711.  
  712. /*****************************************************************************
  713.  redisplay_move_cursor
  714.  
  715.  For the given window W, move the cursor to NEW_POINT.  Returns a
  716.  boolean indicating success or failure.
  717.  ****************************************************************************/
  718.  
  719. #define ADJ_BUFPOS (rb->bufpos + dl->offset)
  720. #define ADJ_ENDPOS (rb->endpos + dl->offset)
  721.  
  722. int
  723. redisplay_move_cursor (struct window *w, Bufpos new_point, int no_output_end)
  724. {
  725.   struct frame *f = XFRAME (w->frame);
  726.   struct device *d = XDEVICE (f->device);
  727.  
  728.   display_line_dynarr *cla = window_display_lines (w, CURRENT_DISP);
  729.   struct display_line *dl;
  730.   struct display_block *db;
  731.   struct rune *rb;
  732.  
  733.   int x = w->last_point_x[CURRENT_DISP];
  734.   int y = w->last_point_y[CURRENT_DISP];
  735.  
  736.   if (y < 0 || y >= Dynarr_length (cla))
  737.     return 0;
  738.  
  739.   dl = Dynarr_atp (cla, y);
  740.   db = get_display_block_from_line (dl, TEXT);
  741.  
  742.   if (x < 0 || x >= Dynarr_length (db->runes))
  743.     return 0;
  744.  
  745.   rb = Dynarr_atp (db->runes, x);
  746.  
  747.   if (rb->cursor_type == CURSOR_OFF)
  748.     return 0;
  749.   else if (ADJ_BUFPOS == new_point
  750.        || (ADJ_ENDPOS && (new_point >= ADJ_BUFPOS)
  751.            && (new_point <= ADJ_ENDPOS)))
  752.     {
  753.       w->last_point_x[CURRENT_DISP] = x;
  754.       w->last_point_y[CURRENT_DISP] = y;
  755.       Fset_marker (w->last_point[CURRENT_DISP], make_number (ADJ_BUFPOS),
  756.            w->buffer);
  757.       dl->cursor_elt = x;
  758.       return 1;
  759.     }
  760.   else
  761.     {
  762.       DEVMETH (d, output_begin, (d));
  763.  
  764.       /* #### This is a gross kludge.  Cursor handling is such a royal
  765.          pain in the ass. */
  766.       if (rb->type == DGLYPH &&
  767.       (EQ (rb->object.dglyph.glyph, Vtruncation_glyph) ||
  768.        EQ (rb->object.dglyph.glyph, Vcontinuation_glyph)))
  769.     rb->cursor_type = NO_CURSOR;
  770.       else
  771.     rb->cursor_type = CURSOR_OFF;
  772.       dl->cursor_elt = -1;
  773.       output_display_line (w, 0, cla, y, rb->xpos, rb->xpos + rb->width);
  774.     }
  775.  
  776.   w->last_point_x[CURRENT_DISP] = -1;
  777.   w->last_point_y[CURRENT_DISP] = -1;
  778.   Fset_marker (w->last_point[CURRENT_DISP], Qnil, w->buffer);
  779.  
  780.   /* If this isn't the selected frame, then erasing the old cursor is
  781.      all we actually had to do. */
  782.   if (w != XWINDOW (FRAME_SELECTED_WINDOW (device_selected_frame (d))))
  783.     {
  784.       if (!no_output_end)
  785.     DEVMETH (d, output_end, (d));
  786.  
  787.       return 1;
  788.     }
  789.  
  790.   /* This should only occur in the minibuffer. */
  791.   if (new_point == 0)
  792.     {
  793.       w->last_point_x[CURRENT_DISP] = 0;
  794.       w->last_point_y[CURRENT_DISP] = y;
  795.       Fset_marker (w->last_point[CURRENT_DISP], Qzero, w->buffer);
  796.  
  797.       rb = Dynarr_atp (db->runes, 0);
  798.       rb->cursor_type = CURSOR_ON;
  799.       dl->cursor_elt = 0;
  800.  
  801.       output_display_line (w, 0, cla, y, rb->xpos, rb->xpos + rb->width);
  802.  
  803.       if (!no_output_end)
  804.     DEVMETH (d, output_end, (d));
  805.       return 1;
  806.     }
  807.   else
  808.     {
  809.       int cur_rb = 0;
  810.       int first = 0;
  811.       int cur_dl, up;
  812.  
  813.       if (ADJ_BUFPOS < new_point)
  814.     {
  815.       up = 1;
  816.       cur_rb = x + 1;
  817.       cur_dl = y;
  818.     }
  819.       else /* (rb->bufpos + dl->offset) > new_point */
  820.     {
  821.       up = 0;
  822.  
  823.       if (!x)
  824.         {
  825.           cur_dl = y - 1;
  826.           first = 0;
  827.         }
  828.       else
  829.         {
  830.           cur_rb = x - 1;
  831.           cur_dl = y;
  832.           first = 1;
  833.         }
  834.     }
  835.  
  836.       while ((up ? (cur_dl < Dynarr_length (cla)) : (cur_dl >= 0)))
  837.     {
  838.       dl = Dynarr_atp (cla, cur_dl);
  839.       db = get_display_block_from_line (dl, TEXT);
  840.  
  841.       if (!up && !first)
  842.         cur_rb = Dynarr_length (db->runes) - 1;
  843.  
  844.       while ((!scroll_on_clipped_lines || !dl->clip) &&
  845.          (up ? (cur_rb < Dynarr_length (db->runes)) : (cur_rb >= 0)))
  846.         {
  847.           rb = Dynarr_atp (db->runes, cur_rb);
  848.  
  849.           if (rb->cursor_type != IGNORE_CURSOR
  850.           && rb->cursor_type != NO_CURSOR &&
  851.           (ADJ_BUFPOS == new_point
  852.            || (ADJ_ENDPOS && (new_point >= ADJ_BUFPOS)
  853.                && (new_point <= ADJ_BUFPOS))))
  854.         {
  855.           rb->cursor_type = CURSOR_ON;
  856.           dl->cursor_elt = cur_rb;
  857.           
  858.  
  859.           output_display_line (w, 0, cla, cur_dl, rb->xpos,
  860.                        rb->xpos + rb->width);
  861.  
  862.           w->last_point_x[CURRENT_DISP] = cur_rb;
  863.           w->last_point_y[CURRENT_DISP] = cur_dl;
  864.           Fset_marker (w->last_point[CURRENT_DISP],
  865.                    make_number (ADJ_BUFPOS), w->buffer);
  866.  
  867.           if (!no_output_end)
  868.             DEVMETH (d, output_end, (d));
  869.           return 1;
  870.         }
  871.  
  872.           (up ? cur_rb++ : cur_rb--);
  873.         }
  874.  
  875.       (up ? (cur_rb = 0) : (first = 0));
  876.       (up ? cur_dl++ : cur_dl--);
  877.     }
  878.     }
  879.  
  880.   if (!no_output_end)
  881.     DEVMETH (d, output_end, (d));
  882.   return 0;
  883. }
  884. #undef ADJ_BUFPOS
  885. #undef ADJ_ENDPOS
  886.  
  887. /*****************************************************************************
  888.  redraw_cursor_in_window
  889.  
  890.  For the given window W, redraw the cursor if it is contained within
  891.  the window.
  892.  ****************************************************************************/
  893. static void
  894. redraw_cursor_in_window (struct window *w, int run_end_begin_meths)
  895. {
  896.   struct frame *f = XFRAME (w->frame);
  897.   struct device *d = XDEVICE (f->device);
  898.  
  899.   display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
  900.   struct display_line *dl;
  901.   struct display_block *db;
  902.   struct rune *rb;
  903.  
  904.   int x = w->last_point_x[CURRENT_DISP];
  905.   int y = w->last_point_y[CURRENT_DISP];
  906.  
  907.   if (y < 0 || y >= Dynarr_length (dla))
  908.     return;
  909.  
  910.   if (MINI_WINDOW_P (w) && f != device_selected_frame (d))
  911.     return;
  912.  
  913.   dl = Dynarr_atp (dla, y);
  914.   db = get_display_block_from_line (dl, TEXT);
  915.  
  916.   if (x < 0 || x >= Dynarr_length (db->runes))
  917.     return;
  918.  
  919.   rb = Dynarr_atp (db->runes, x);
  920.  
  921.   /* Don't call the output routine if the block isn't actually the
  922.      cursor. */
  923.   if (rb->cursor_type == CURSOR_ON)
  924.     {
  925.       if (run_end_begin_meths)
  926.     DEVMETH (d, output_begin, (d));
  927.  
  928.       output_display_line (w, 0, dla, y, rb->xpos, rb->xpos + rb->width);
  929.  
  930.       if (run_end_begin_meths)
  931.     DEVMETH (d, output_end, (d));
  932.     }
  933. }
  934.  
  935. /*****************************************************************************
  936.  redisplay_redraw_cursor
  937.  
  938.  For the given frame F, redraw the cursor on the selected window.
  939.  This is used to update the cursor after focus changes.
  940.  ****************************************************************************/
  941. void
  942. redisplay_redraw_cursor (struct frame *f, int run_end_begin_meths)
  943. {
  944.   struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
  945.  
  946.   redraw_cursor_in_window (w, run_end_begin_meths);
  947. }
  948.  
  949. /*****************************************************************************
  950.  redisplay_clear_top_of_window
  951.  
  952.  If window is topmost, clear the internal border above it.
  953.  ****************************************************************************/
  954. static void
  955. redisplay_clear_top_of_window (struct window *w)
  956. {
  957.   Lisp_Object window;
  958.   XSETWINDOW (window, w);
  959.  
  960.   if (!NILP (Fwindow_highest_p (window)))
  961.     {
  962.       struct frame *f = XFRAME (w->frame);
  963.       struct device *d = XDEVICE (f->device);
  964.       int x, y, width, height;
  965.  
  966.       x = w->pixel_left;
  967.       width = w->pixel_width;
  968.  
  969.       if (window_is_leftmost (w))
  970.     {
  971.       x -= FRAME_BORDER_WIDTH (f);
  972.       width += FRAME_BORDER_WIDTH (f);
  973.     }
  974.       if (window_is_rightmost (w))
  975.     width += FRAME_BORDER_WIDTH (f);
  976.       
  977.       y = FRAME_TOP_BORDER_START (f) - 1;
  978.       height = FRAME_BORDER_HEIGHT (f) + 1;
  979.  
  980.       DEVMETH (d, clear_region, (window, DEFAULT_INDEX, x, y, width, height));
  981.     }
  982. }
  983.  
  984. /*****************************************************************************
  985.  redisplay_clear_bottom_of_window
  986.  
  987.  Clear window from right below the last display line to right above
  988.  the modeline.  The calling function can limit the area actually
  989.  erased by setting min_start and/or max_end to positive values.
  990.  ****************************************************************************/
  991. void
  992. redisplay_clear_bottom_of_window (struct window *w, display_line_dynarr *ddla,
  993.                   int min_start, int max_end)
  994. {
  995.   struct frame *f = XFRAME (w->frame);
  996.   struct device *d = XDEVICE (f->device);
  997.   int ypos1, ypos2;
  998.   int ddla_len = Dynarr_length (ddla);
  999.  
  1000.   ypos2 = WINDOW_TEXT_BOTTOM (w);
  1001.   /* This adjustment is to catch the intersection of any scrollbars. */
  1002.   if (f->windows_structure_changed && !f->scrollbar_on_top)
  1003.     ypos2 += window_scrollbar_height (w);
  1004.  
  1005.   if (ddla_len)
  1006.     {
  1007.       if (ddla_len == 1 && Dynarr_atp (ddla, 0)->modeline)
  1008.     {
  1009.       ypos1 = WINDOW_TEXT_TOP (w);
  1010.       /* This adjustment is to catch the intersection of any scrollbars. */
  1011.       if (f->windows_structure_changed && f->scrollbar_on_top)
  1012.         ypos1 -= window_scrollbar_height (w);
  1013.     }
  1014.       else
  1015.     {
  1016.       struct display_line *dl = Dynarr_atp (ddla, ddla_len - 1);
  1017.       ypos1 = dl->ypos + dl->descent - dl->clip;
  1018.     }
  1019.     }
  1020.   else
  1021.     ypos1 = WINDOW_TEXT_TOP (w);
  1022.  
  1023.   /* #### See if this can be made conditional on the frame
  1024.      changing size. */
  1025.   if (MINI_WINDOW_P (w))
  1026.     ypos2 += FRAME_BORDER_HEIGHT (f);
  1027.  
  1028.   if (min_start >= 0 && ypos1 < min_start)
  1029.     ypos1 = min_start;
  1030.   if (max_end >= 0 && ypos2 > max_end)
  1031.     ypos2 = max_end;
  1032.  
  1033.   if (ypos2 <= ypos1)
  1034.     return;
  1035.  
  1036.   DEVMETH (d, clear_to_window_end, (w, ypos1, ypos2));
  1037. }
  1038.  
  1039. /*****************************************************************************
  1040.  redisplay_update_line
  1041.  
  1042.  This is used during incremental updates to update a single line and
  1043.  correct the offsets on all lines below it.  At the moment
  1044.  update_values is false if we are only updating the modeline.
  1045.  ****************************************************************************/
  1046. void
  1047. redisplay_update_line (struct window *w, int first_line, int last_line,
  1048.                int update_values)
  1049. {
  1050.   struct frame *f = XFRAME (w->frame);
  1051.   struct device *d = XDEVICE (f->device);
  1052.  
  1053.   display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
  1054.   display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
  1055.  
  1056.   DEVMETH (d, output_begin, (d));
  1057.  
  1058.   while (first_line <= last_line)
  1059.     {
  1060.       Charcount old_len = (Dynarr_atp (cdla, first_line)->end_bufpos -
  1061.                Dynarr_atp (cdla, first_line)->bufpos);
  1062.       Charcount new_len = (Dynarr_atp (ddla, first_line)->end_bufpos -
  1063.                Dynarr_atp (ddla, first_line)->bufpos);
  1064.  
  1065.       assert (Dynarr_length (cdla) == Dynarr_length (ddla));
  1066.  
  1067.       /* Output the changes. */
  1068.       output_display_line (w, cdla, ddla, first_line, -1, -1);
  1069.  
  1070.       /* Update the offsets. */
  1071.       if (update_values)
  1072.     {
  1073.       int cur_line = first_line + 1;
  1074.       while (cur_line < Dynarr_length (cdla))
  1075.         {
  1076.           Dynarr_atp (cdla, cur_line)->offset += (new_len - old_len);
  1077.           Dynarr_atp (ddla, cur_line)->offset += (new_len - old_len);
  1078.           cur_line++;
  1079.         }
  1080.     }
  1081.  
  1082.       /* Update the window_end_pos and other settings. */
  1083.       if (update_values)
  1084.     {
  1085.       w->window_end_pos[CURRENT_DISP] -= (new_len - old_len);
  1086.  
  1087.       if (Dynarr_atp (ddla, first_line)->cursor_elt != -1)
  1088.         {
  1089.           w->last_point_x[CURRENT_DISP] = w->last_point_x[DESIRED_DISP];
  1090.           w->last_point_y[CURRENT_DISP] = w->last_point_y[DESIRED_DISP];
  1091.         }
  1092.     }
  1093.  
  1094.       first_line++;
  1095.     }
  1096.  
  1097.   /* Update the window max line length.  We have to scan the entire
  1098.      set of display lines otherwise we might not detect if the max is
  1099.      supposed to shrink. */
  1100.   if (update_values)
  1101.     {
  1102.       int line = 0;
  1103.  
  1104.       w->max_line_len = 0;
  1105.       while (line < Dynarr_length (ddla))
  1106.     {
  1107.       struct display_line *dl = Dynarr_atp (ddla, line);
  1108.  
  1109.       if (!dl->modeline)
  1110.         w->max_line_len = max (dl->num_chars, w->max_line_len);
  1111.  
  1112.       line++;
  1113.     }
  1114.     }
  1115.  
  1116.   w->last_modified[CURRENT_DISP] = w->last_modified[DESIRED_DISP];
  1117.   w->last_facechange[CURRENT_DISP] = w->last_facechange[DESIRED_DISP];
  1118.   Fset_marker (w->last_point[CURRENT_DISP],
  1119.            Fmarker_position (w->last_point[DESIRED_DISP]), w->buffer);
  1120.   Fset_marker (w->last_start[CURRENT_DISP],
  1121.            Fmarker_position (w->last_start[DESIRED_DISP]), w->buffer);
  1122.  
  1123.   /* We don't bother updating the vertical scrollbars here.  This
  1124.      gives us a performance increase while having minimal loss of
  1125.      quality to the scrollbar slider size and position since when this
  1126.      function is called we know that the changes to the buffer were
  1127.      very localized.  We have to update the horizontal scrollbars,
  1128.      though, because this routine could cause a change which has a
  1129.      larger impact on their sizing. */
  1130.   /* #### See if we can get away with only calling this if
  1131.      max_line_len is greater than the window_char_width. */
  1132.   update_window_scrollbars (w, NULL, 1, 1);
  1133.  
  1134.   /* This has to be done after we've updated the values.  We don't
  1135.      call output_end for tty frames.  Redisplay will do this after all
  1136.      tty windows have been updated.  This cuts down on cursor
  1137.      flicker. */
  1138.   if (FRAME_IS_TTY (f))
  1139.     redisplay_redraw_cursor (f, 0);
  1140.   else
  1141.     DEVMETH (d, output_end, (d));
  1142. }
  1143.  
  1144. /*****************************************************************************
  1145.  redisplay_output_window
  1146.  
  1147.  For the given window W, ensure that the current display lines are
  1148.  equal to the desired display lines, outputing changes as necessary.
  1149.  
  1150.  #### Fuck me.  This just isn't going to cut it for tty's.  The output
  1151.  decisions for them must be based on the contents of the entire frame
  1152.  because that is how the available output capabilities think.  The
  1153.  solution is relatively simple.  Create redisplay_output_frame.  This
  1154.  will basically merge all of the separate window display structs into
  1155.  a single one for the frame.  This combination structure will be able
  1156.  to be passed to the same output_display_line which works for windows
  1157.  on X frames and the right things will happen.  It just takes time to
  1158.  do.
  1159.  ****************************************************************************/
  1160. void
  1161. redisplay_output_window (struct window *w)
  1162. {
  1163.   struct frame *f = XFRAME (w->frame);
  1164.   struct device *d = XDEVICE (f->device);
  1165.  
  1166.   display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP);
  1167.   display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP);
  1168.  
  1169.   int cdla_len = Dynarr_length (cdla);
  1170.   int ddla_len = Dynarr_length (ddla);
  1171.  
  1172.   int line;
  1173.   int need_to_clear_bottom = 0;
  1174.   int need_to_clear_start = -1;
  1175.   int need_to_clear_end = -1;
  1176.  
  1177.   /* Backgrounds may have changed or windows may have gone away
  1178.      leaving dividers lying around. */
  1179.   if (f->faces_changed
  1180.       || f->windows_structure_changed
  1181.       || w->shadow_thickness_changed)
  1182.     need_to_clear_bottom = 1;
  1183.  
  1184.   /* The first thing we do is determine if we are going to need to
  1185.      clear the bottom of the window.  We only need to do this if the
  1186.      bottom of the current display lines is below the bottom of the
  1187.      desired display lines.  Note that the number of lines is
  1188.      irrelevant.  Only the position matters.  We also clear to the
  1189.      bottom of the window if the modeline has shifted position. */
  1190.   /* #### We can't blindly not clear the bottom if f->clear is true
  1191.      since there might be a window-local background.  However, for
  1192.      those cases where there isn't, clearing the end of the window in
  1193.      this case sucks. */
  1194.   if (!need_to_clear_bottom)
  1195.     {
  1196.       struct display_line *cdl, *ddl;
  1197.  
  1198.       /* If the modeline has changed position or size, clear the bottom
  1199.      of the window. */
  1200.       if (!need_to_clear_bottom)
  1201.     {
  1202.       cdl = ddl = 0;
  1203.  
  1204.       if (cdla_len)
  1205.         cdl = Dynarr_atp (cdla, 0);
  1206.       if (ddla_len)
  1207.         ddl = Dynarr_atp (ddla, 0);
  1208.  
  1209.       if (!cdl || !ddl)
  1210.         need_to_clear_bottom = 1;
  1211.       else if ((!cdl->modeline && ddl->modeline)
  1212.            || (cdl->modeline && !ddl->modeline))
  1213.         need_to_clear_bottom = 1;
  1214.       else if (cdl->ypos != ddl->ypos ||
  1215.            cdl->ascent != ddl->ascent ||
  1216.            cdl->descent != ddl->descent ||
  1217.            cdl->clip != ddl->clip)
  1218.         need_to_clear_bottom = 1;
  1219.  
  1220.       /* #### This kludge is to make sure the modeline shadows get
  1221.          redrawn if the modeline position shifts. */
  1222.       if (need_to_clear_bottom)
  1223.         w->shadow_thickness_changed = 1;
  1224.     }
  1225.  
  1226.       if (!need_to_clear_bottom)
  1227.     {
  1228.       cdl = ddl = 0;
  1229.  
  1230.       if (cdla_len)
  1231.         cdl = Dynarr_atp (cdla, cdla_len - 1);
  1232.       if (ddla_len)
  1233.         ddl = Dynarr_atp (ddla, ddla_len - 1);
  1234.  
  1235.       if (!cdl || !ddl)
  1236.         need_to_clear_bottom = 1;
  1237.       else
  1238.         {
  1239.           int cdl_bottom, ddl_bottom;
  1240.  
  1241.           cdl_bottom = cdl->ypos + cdl->descent;
  1242.           ddl_bottom = ddl->ypos + ddl->descent;
  1243.  
  1244.           if (cdl_bottom > ddl_bottom)
  1245.         {
  1246.           need_to_clear_bottom = 1;
  1247.           need_to_clear_start = ddl_bottom;
  1248.           need_to_clear_end = cdl_bottom;
  1249.         }
  1250.         }
  1251.     }
  1252.     }
  1253.  
  1254.   /* Perform any output initialization. */
  1255.   DEVMETH (d, output_begin, (d));
  1256.  
  1257.   /* If the window's structure has changed clear the internal border
  1258.      above it if it is topmost (the function will check). */
  1259.   if (f->windows_structure_changed)
  1260.     redisplay_clear_top_of_window (w);
  1261.  
  1262.   /* Output each line. */
  1263.   for (line = 0; line < Dynarr_length (ddla); line++)
  1264.     {
  1265.       output_display_line (w, cdla, ddla, line, -1, -1);
  1266.     }
  1267.  
  1268.   /* If the number of display lines has shrunk, adjust. */
  1269.   if (cdla_len > ddla_len)
  1270.     {
  1271.       Dynarr_length (cdla) = ddla_len;
  1272.     }
  1273.  
  1274.   /* Output a vertical divider between windows, if necessary. */
  1275.   if (window_needs_vertical_divider (w)
  1276.       && (f->windows_structure_changed || f->clear))
  1277.     {
  1278.       DEVMETH (d, output_vertical_divider, (w, f->windows_structure_changed));
  1279.     }
  1280.  
  1281.   /* Clear the rest of the window, if necessary. */
  1282.   if (need_to_clear_bottom)
  1283.     {
  1284.       redisplay_clear_bottom_of_window (w, ddla, need_to_clear_start,
  1285.                     need_to_clear_end);
  1286.     }
  1287.  
  1288.   w->window_end_pos[CURRENT_DISP] = w->window_end_pos[DESIRED_DISP];
  1289.   Fset_marker (w->start[CURRENT_DISP],
  1290.            make_number (marker_position (w->start[DESIRED_DISP])),
  1291.            w->buffer);
  1292.   Fset_marker (w->pointm[CURRENT_DISP],
  1293.            make_number (marker_position (w->pointm[DESIRED_DISP])),
  1294.            w->buffer);
  1295.   w->last_modified[CURRENT_DISP] = w->last_modified[DESIRED_DISP];
  1296.   w->last_facechange[CURRENT_DISP] = w->last_facechange[DESIRED_DISP];
  1297.   Fset_marker (w->last_start[CURRENT_DISP],
  1298.            Fmarker_position (w->last_start[DESIRED_DISP]), w->buffer);
  1299.   Fset_marker (w->last_point[CURRENT_DISP],
  1300.            Fmarker_position (w->last_point[DESIRED_DISP]), w->buffer);
  1301.   w->last_point_x[CURRENT_DISP] = w->last_point_x[DESIRED_DISP];
  1302.   w->last_point_y[CURRENT_DISP] = w->last_point_y[DESIRED_DISP];
  1303.   w->shadow_thickness_changed = 0;
  1304.  
  1305.   set_window_display_buffer (w, XBUFFER (w->buffer));
  1306.   find_window_mirror (w)->truncate_win = window_truncation_on (w);
  1307.  
  1308.   /* Overkill on invalidating the cache.  It is very bad for it to not
  1309.      get invalidated when it should be. */
  1310.   INVALIDATE_DEVICE_PIXEL_TO_GLYPH_CACHE (d);
  1311.  
  1312.   /* We don't call output_end for tty frames.  Redisplay will do this
  1313.      after all tty windows have been updated.  This cuts down on
  1314.      cursor flicker. */
  1315.   if (FRAME_IS_TTY (f))
  1316.     redisplay_redraw_cursor (f, 0);
  1317.   else
  1318.     DEVMETH (d, output_end, (d));
  1319.  
  1320.   update_window_scrollbars (w, NULL, !MINI_WINDOW_P (w), 0);
  1321. }
  1322.